<?php
class CBlogComments extends Zend_Db_Table
{
	protected $_name;
	protected $_primary;

	public function __construct()
	{
		$this->_name = R_PRE."blogcomments";
		$this->_primary = "comment_id";
		parent::__construct();
		
	}

	public function add($data)
	{
		$commentId=$this->insert($data);		
		return $commentId;
	}

	
	public function delete($itemidArray)
	{		
		$db=$this->getAdapter();
		$itemidString=join(',',$itemidArray);
		$result=$db->query("DELETE FROM $this->_name WHERE comment_id IN ($itemidString)");
		return $result;
	}
	
	public function getComments($page, $pageNum, $blogId)
	{
		$where = array('blog_id = ?'=>$blogId);
		$order = 'comment_id desc';	
		$offset = ($page -1) * $pageNum;
		return $this->fetchAll($where, $order, $pageNum, $offset);
	}
	
	public function getCommentsCounts($blogId)
	{
		$where = array('blog_id = ?'=>$blogId);		
		$result = $this->fetchAll($where);
		
		return count($result);
	}
	
	public function getCommentsCount($pageNum, $blogId)
	{
		$where = array('blog_id = ?'=>$blogId);		
		$result = $this->fetchAll($where);
		
		return ceil(count($result)/$pageNum);
	}
}